<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.3.5 - src/luac.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - luac.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.3.5</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">236</td>
            <td class="headerCovTableEntry">253</td>
            <td class="headerCovTableEntryHi">93.3 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:17</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: luac.c,v 1.76 2018/06/19 01:32:02 lhf Exp $
<span class="lineNum">       3 </span>            : ** Lua compiler (saves bytecodes to files; also lists bytecodes)
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #define luac_c
<span class="lineNum">       8 </span>            : #define LUA_CORE
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;lprefix.h&quot;
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : #include &lt;ctype.h&gt;
<span class="lineNum">      13 </span>            : #include &lt;errno.h&gt;
<span class="lineNum">      14 </span>            : #include &lt;stdio.h&gt;
<span class="lineNum">      15 </span>            : #include &lt;stdlib.h&gt;
<span class="lineNum">      16 </span>            : #include &lt;string.h&gt;
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      19 </span>            : #include &quot;lauxlib.h&quot;
<span class="lineNum">      20 </span>            : 
<span class="lineNum">      21 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      22 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      23 </span>            : #include &quot;lundump.h&quot;
<span class="lineNum">      24 </span>            : 
<span class="lineNum">      25 </span>            : static void PrintFunction(const Proto* f, int full);
<span class="lineNum">      26 </span>            : #define luaU_print      PrintFunction
<span class="lineNum">      27 </span>            : 
<span class="lineNum">      28 </span>            : #define PROGNAME        &quot;luac&quot;                /* default program name */
<span class="lineNum">      29 </span>            : #define OUTPUT          PROGNAME &quot;.out&quot;       /* default output file */
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            : static int listing=0;                   /* list bytecodes? */
<span class="lineNum">      32 </span>            : static int dumping=1;                   /* dump bytecodes? */
<span class="lineNum">      33 </span>            : static int stripping=0;                 /* strip debug information? */
<span class="lineNum">      34 </span>            : static char Output[]={ OUTPUT };        /* default output file name */
<span class="lineNum">      35 </span>            : static const char* output=Output;       /* actual output file name */
<span class="lineNum">      36 </span>            : static const char* progname=PROGNAME;   /* actual program name */
<span class="lineNum">      37 </span>            : 
<span class="lineNum">      38 </span><span class="lineCov">          9 : static void fatal(const char* message)</span>
<span class="lineNum">      39 </span>            : {
<span class="lineNum">      40 </span><span class="lineCov">          9 :  fprintf(stderr,&quot;%s: %s\n&quot;,progname,message);</span>
<span class="lineNum">      41 </span><span class="lineCov">          9 :  exit(EXIT_FAILURE);</span>
<span class="lineNum">      42 </span>            : }
<span class="lineNum">      43 </span>            : 
<span class="lineNum">      44 </span><span class="lineNoCov">          0 : static void cannot(const char* what)</span>
<span class="lineNum">      45 </span>            : {
<span class="lineNum">      46 </span><span class="lineNoCov">          0 :  fprintf(stderr,&quot;%s: cannot %s %s: %s\n&quot;,progname,what,output,strerror(errno));</span>
<span class="lineNum">      47 </span><span class="lineNoCov">          0 :  exit(EXIT_FAILURE);</span>
<span class="lineNum">      48 </span>            : }
<span class="lineNum">      49 </span>            : 
<span class="lineNum">      50 </span><span class="lineCov">          2 : static void usage(const char* message)</span>
<span class="lineNum">      51 </span>            : {
<span class="lineNum">      52 </span><span class="lineCov">          2 :  if (*message=='-')</span>
<span class="lineNum">      53 </span><span class="lineCov">          2 :   fprintf(stderr,&quot;%s: unrecognized option '%s'\n&quot;,progname,message);</span>
<span class="lineNum">      54 </span>            :  else
<span class="lineNum">      55 </span><span class="lineNoCov">          0 :   fprintf(stderr,&quot;%s: %s\n&quot;,progname,message);</span>
<span class="lineNum">      56 </span><span class="lineCov">          2 :  fprintf(stderr,</span>
<span class="lineNum">      57 </span>            :   &quot;usage: %s [options] [filenames]\n&quot;
<span class="lineNum">      58 </span>            :   &quot;Available options are:\n&quot;
<span class="lineNum">      59 </span>            :   &quot;  -l       list (use -l -l for full listing)\n&quot;
<span class="lineNum">      60 </span>            :   &quot;  -o name  output to file 'name' (default is \&quot;%s\&quot;)\n&quot;
<span class="lineNum">      61 </span>            :   &quot;  -p       parse only\n&quot;
<span class="lineNum">      62 </span>            :   &quot;  -s       strip debug information\n&quot;
<span class="lineNum">      63 </span>            :   &quot;  -v       show version information\n&quot;
<span class="lineNum">      64 </span>            :   &quot;  --       stop handling options\n&quot;
<span class="lineNum">      65 </span>            :   &quot;  -        stop handling options and process stdin\n&quot;
<span class="lineNum">      66 </span>            :   ,progname,Output);
<span class="lineNum">      67 </span><span class="lineCov">          2 :  exit(EXIT_FAILURE);</span>
<span class="lineNum">      68 </span>            : }
<span class="lineNum">      69 </span>            : 
<span class="lineNum">      70 </span>            : #define IS(s)   (strcmp(argv[i],s)==0)
<span class="lineNum">      71 </span>            : 
<span class="lineNum">      72 </span><span class="lineCov">         24 : static int doargs(int argc, char* argv[])</span>
<span class="lineNum">      73 </span>            : {
<span class="lineNum">      74 </span>            :  int i;
<span class="lineNum">      75 </span><span class="lineCov">         24 :  int version=0;</span>
<span class="lineNum">      76 </span><span class="lineCov">         24 :  if (argv[0]!=NULL &amp;&amp; *argv[0]!=0) progname=argv[0];</span>
<span class="lineNum">      77 </span><span class="lineCov">         43 :  for (i=1; i&lt;argc; i++)</span>
<span class="lineNum">      78 </span>            :  {
<span class="lineNum">      79 </span><span class="lineCov">         41 :   if (*argv[i]!='-')                    /* end of options; keep it */</span>
<span class="lineNum">      80 </span><span class="lineCov">         17 :    break;</span>
<span class="lineNum">      81 </span><span class="lineCov">         24 :   else if (IS(&quot;--&quot;))                  /* end of options; skip it */</span>
<span class="lineNum">      82 </span>            :   {
<span class="lineNum">      83 </span><span class="lineCov">          1 :    ++i;</span>
<span class="lineNum">      84 </span><span class="lineCov">          1 :    if (version) ++version;</span>
<span class="lineNum">      85 </span><span class="lineCov">          1 :    break;</span>
<span class="lineNum">      86 </span>            :   }
<span class="lineNum">      87 </span><span class="lineCov">         23 :   else if (IS(&quot;-&quot;))                   /* end of options; use stdin */</span>
<span class="lineNum">      88 </span><span class="lineCov">          2 :    break;</span>
<span class="lineNum">      89 </span><span class="lineCov">         21 :   else if (IS(&quot;-l&quot;))                  /* list */</span>
<span class="lineNum">      90 </span><span class="lineCov">          8 :    ++listing;</span>
<span class="lineNum">      91 </span><span class="lineCov">         13 :   else if (IS(&quot;-o&quot;))                  /* output file */</span>
<span class="lineNum">      92 </span>            :   {
<span class="lineNum">      93 </span><span class="lineCov">          3 :    output=argv[++i];</span>
<span class="lineNum">      94 </span><span class="lineCov">          3 :    if (output==NULL || *output==0 || (*output=='-' &amp;&amp; output[1]!=0))</span>
<span class="lineNum">      95 </span><span class="lineNoCov">          0 :     usage(&quot;'-o' needs argument&quot;);</span>
<span class="lineNum">      96 </span><span class="lineCov">          3 :    if (IS(&quot;-&quot;)) output=NULL;</span>
<span class="lineNum">      97 </span>            :   }
<span class="lineNum">      98 </span><span class="lineCov">         10 :   else if (IS(&quot;-p&quot;))                  /* parse only */</span>
<span class="lineNum">      99 </span><span class="lineCov">          3 :    dumping=0;</span>
<span class="lineNum">     100 </span><span class="lineCov">          7 :   else if (IS(&quot;-s&quot;))                  /* strip debug information */</span>
<span class="lineNum">     101 </span><span class="lineCov">          2 :    stripping=1;</span>
<span class="lineNum">     102 </span><span class="lineCov">          5 :   else if (IS(&quot;-v&quot;))                  /* show version */</span>
<span class="lineNum">     103 </span><span class="lineCov">          3 :    ++version;</span>
<span class="lineNum">     104 </span>            :   else                                  /* unknown option */
<span class="lineNum">     105 </span><span class="lineCov">          2 :    usage(argv[i]);</span>
<span class="lineNum">     106 </span>            :  }
<span class="lineNum">     107 </span><span class="lineCov">         22 :  if (i==argc &amp;&amp; (listing || !dumping))</span>
<span class="lineNum">     108 </span>            :  {
<span class="lineNum">     109 </span><span class="lineCov">          1 :   dumping=0;</span>
<span class="lineNum">     110 </span><span class="lineCov">          1 :   argv[--i]=Output;</span>
<span class="lineNum">     111 </span>            :  }
<span class="lineNum">     112 </span><span class="lineCov">         22 :  if (version)</span>
<span class="lineNum">     113 </span>            :  {
<span class="lineNum">     114 </span><span class="lineCov">          3 :   printf(&quot;%s\n&quot;,LUA_COPYRIGHT);</span>
<span class="lineNum">     115 </span><span class="lineCov">          3 :   if (version==argc-1) exit(EXIT_SUCCESS);</span>
<span class="lineNum">     116 </span>            :  }
<span class="lineNum">     117 </span><span class="lineCov">         20 :  return i;</span>
<span class="lineNum">     118 </span>            : }
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span>            : #define FUNCTION &quot;(function()end)();&quot;
<span class="lineNum">     121 </span>            : 
<span class="lineNum">     122 </span><span class="lineCov">          3 : static const char* reader(lua_State *L, void *ud, size_t *size)</span>
<span class="lineNum">     123 </span>            : {
<span class="lineNum">     124 </span>            :  UNUSED(L);
<span class="lineNum">     125 </span><span class="lineCov">          3 :  if ((*(int*)ud)--)</span>
<span class="lineNum">     126 </span>            :  {
<span class="lineNum">     127 </span><span class="lineCov">          2 :   *size=sizeof(FUNCTION)-1;</span>
<span class="lineNum">     128 </span><span class="lineCov">          2 :   return FUNCTION;</span>
<span class="lineNum">     129 </span>            :  }
<span class="lineNum">     130 </span>            :  else
<span class="lineNum">     131 </span>            :  {
<span class="lineNum">     132 </span><span class="lineCov">          1 :   *size=0;</span>
<span class="lineNum">     133 </span><span class="lineCov">          1 :   return NULL;</span>
<span class="lineNum">     134 </span>            :  }
<span class="lineNum">     135 </span>            : }
<span class="lineNum">     136 </span>            : 
<span class="lineNum">     137 </span>            : #define toproto(L,i) getproto(L-&gt;top+(i))
<span class="lineNum">     138 </span>            : 
<span class="lineNum">     139 </span><span class="lineCov">         11 : static const Proto* combine(lua_State* L, int n)</span>
<span class="lineNum">     140 </span>            : {
<span class="lineNum">     141 </span><span class="lineCov">         11 :  if (n==1)</span>
<span class="lineNum">     142 </span><span class="lineCov">         10 :   return toproto(L,-1);</span>
<span class="lineNum">     143 </span>            :  else
<span class="lineNum">     144 </span>            :  {
<span class="lineNum">     145 </span>            :   Proto* f;
<span class="lineNum">     146 </span><span class="lineCov">          1 :   int i=n;</span>
<span class="lineNum">     147 </span><span class="lineCov">          1 :   if (lua_load(L,reader,&amp;i,&quot;=(&quot; PROGNAME &quot;)&quot;,NULL)!=LUA_OK) fatal(lua_tostring(L,-1));</span>
<span class="lineNum">     148 </span><span class="lineCov">          1 :   f=toproto(L,-1);</span>
<span class="lineNum">     149 </span><span class="lineCov">          3 :   for (i=0; i&lt;n; i++)</span>
<span class="lineNum">     150 </span>            :   {
<span class="lineNum">     151 </span><span class="lineCov">          2 :    f-&gt;p[i]=toproto(L,i-n-1);</span>
<span class="lineNum">     152 </span><span class="lineCov">          2 :    if (f-&gt;p[i]-&gt;sizeupvalues&gt;0) f-&gt;p[i]-&gt;upvalues[0].instack=0;</span>
<span class="lineNum">     153 </span>            :   }
<span class="lineNum">     154 </span><span class="lineCov">          1 :   f-&gt;sizelineinfo=0;</span>
<span class="lineNum">     155 </span><span class="lineCov">          1 :   return f;</span>
<span class="lineNum">     156 </span>            :  }
<span class="lineNum">     157 </span>            : }
<span class="lineNum">     158 </span>            : 
<span class="lineNum">     159 </span><span class="lineCov">        544 : static int writer(lua_State* L, const void* p, size_t size, void* u)</span>
<span class="lineNum">     160 </span>            : {
<span class="lineNum">     161 </span>            :  UNUSED(L);
<span class="lineNum">     162 </span><span class="lineCov">        544 :  return (fwrite(p,size,1,(FILE*)u)!=1) &amp;&amp; (size!=0);</span>
<span class="lineNum">     163 </span>            : }
<span class="lineNum">     164 </span>            : 
<span class="lineNum">     165 </span><span class="lineCov">         20 : static int pmain(lua_State* L)</span>
<span class="lineNum">     166 </span>            : {
<span class="lineNum">     167 </span><span class="lineCov">         20 :  int argc=(int)lua_tointeger(L,1);</span>
<span class="lineNum">     168 </span><span class="lineCov">         20 :  char** argv=(char**)lua_touserdata(L,2);</span>
<span class="lineNum">     169 </span>            :  const Proto* f;
<span class="lineNum">     170 </span>            :  int i;
<span class="lineNum">     171 </span><span class="lineCov">         20 :  if (!lua_checkstack(L,argc)) fatal(&quot;too many input files&quot;);</span>
<span class="lineNum">     172 </span><span class="lineCov">         32 :  for (i=0; i&lt;argc; i++)</span>
<span class="lineNum">     173 </span>            :  {
<span class="lineNum">     174 </span><span class="lineCov">         21 :   const char* filename=IS(&quot;-&quot;) ? NULL : argv[i];</span>
<span class="lineNum">     175 </span><span class="lineCov">         21 :   if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));</span>
<span class="lineNum">     176 </span>            :  }
<span class="lineNum">     177 </span><span class="lineCov">         11 :  f=combine(L,argc);</span>
<span class="lineNum">     178 </span><span class="lineCov">         11 :  if (listing) luaU_print(f,listing&gt;1);</span>
<span class="lineNum">     179 </span><span class="lineCov">         11 :  if (dumping)</span>
<span class="lineNum">     180 </span>            :  {
<span class="lineNum">     181 </span><span class="lineCov">          8 :   FILE* D= (output==NULL) ? stdout : fopen(output,&quot;wb&quot;);</span>
<span class="lineNum">     182 </span><span class="lineCov">          8 :   if (D==NULL) cannot(&quot;open&quot;);</span>
<span class="lineNum">     183 </span>            :   lua_lock(L);
<span class="lineNum">     184 </span><span class="lineCov">          8 :   luaU_dump(L,f,writer,D,stripping);</span>
<span class="lineNum">     185 </span>            :   lua_unlock(L);
<span class="lineNum">     186 </span><span class="lineCov">          8 :   if (ferror(D)) cannot(&quot;write&quot;);</span>
<span class="lineNum">     187 </span><span class="lineCov">          8 :   if (fclose(D)) cannot(&quot;close&quot;);</span>
<span class="lineNum">     188 </span>            :  }
<span class="lineNum">     189 </span><span class="lineCov">         11 :  return 0;</span>
<span class="lineNum">     190 </span>            : }
<span class="lineNum">     191 </span>            : 
<span class="lineNum">     192 </span><span class="lineCov">         24 : int main(int argc, char* argv[])</span>
<span class="lineNum">     193 </span>            : {
<span class="lineNum">     194 </span>            :  lua_State* L;
<span class="lineNum">     195 </span><span class="lineCov">         24 :  int i=doargs(argc,argv);</span>
<span class="lineNum">     196 </span><span class="lineCov">         20 :  argc-=i; argv+=i;</span>
<span class="lineNum">     197 </span><span class="lineCov">         20 :  if (argc&lt;=0) usage(&quot;no input files given&quot;);</span>
<span class="lineNum">     198 </span><span class="lineCov">         20 :  L=luaL_newstate();</span>
<span class="lineNum">     199 </span><span class="lineCov">         20 :  if (L==NULL) fatal(&quot;cannot create state: not enough memory&quot;);</span>
<span class="lineNum">     200 </span><span class="lineCov">         20 :  lua_pushcfunction(L,&amp;pmain);</span>
<span class="lineNum">     201 </span><span class="lineCov">         20 :  lua_pushinteger(L,argc);</span>
<span class="lineNum">     202 </span><span class="lineCov">         20 :  lua_pushlightuserdata(L,argv);</span>
<span class="lineNum">     203 </span><span class="lineCov">         20 :  if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));</span>
<span class="lineNum">     204 </span><span class="lineCov">         11 :  lua_close(L);</span>
<span class="lineNum">     205 </span><span class="lineCov">         11 :  return EXIT_SUCCESS;</span>
<span class="lineNum">     206 </span>            : }
<span class="lineNum">     207 </span>            : 
<span class="lineNum">     208 </span>            : /*
<span class="lineNum">     209 </span>            : ** $Id: luac.c,v 1.76 2018/06/19 01:32:02 lhf Exp $
<span class="lineNum">     210 </span>            : ** print bytecodes
<span class="lineNum">     211 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">     212 </span>            : */
<span class="lineNum">     213 </span>            : 
<span class="lineNum">     214 </span>            : #include &lt;ctype.h&gt;
<span class="lineNum">     215 </span>            : #include &lt;stdio.h&gt;
<span class="lineNum">     216 </span>            : 
<span class="lineNum">     217 </span>            : #define luac_c
<span class="lineNum">     218 </span>            : #define LUA_CORE
<span class="lineNum">     219 </span>            : 
<span class="lineNum">     220 </span>            : #include &quot;ldebug.h&quot;
<span class="lineNum">     221 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">     222 </span>            : #include &quot;lopcodes.h&quot;
<span class="lineNum">     223 </span>            : 
<span class="lineNum">     224 </span>            : #define VOID(p)         ((const void*)(p))
<span class="lineNum">     225 </span>            : 
<span class="lineNum">     226 </span><span class="lineCov">         44 : static void PrintString(const TString* ts)</span>
<span class="lineNum">     227 </span>            : {
<span class="lineNum">     228 </span><span class="lineCov">         44 :  const char* s=getstr(ts);</span>
<span class="lineNum">     229 </span><span class="lineCov">         44 :  size_t i,n=tsslen(ts);</span>
<span class="lineNum">     230 </span><span class="lineCov">         44 :  printf(&quot;%c&quot;,'&quot;');</span>
<span class="lineNum">     231 </span><span class="lineCov">        263 :  for (i=0; i&lt;n; i++)</span>
<span class="lineNum">     232 </span>            :  {
<span class="lineNum">     233 </span><span class="lineCov">        219 :   int c=(int)(unsigned char)s[i];</span>
<span class="lineNum">     234 </span><span class="lineCov">        219 :   switch (c)</span>
<span class="lineNum">     235 </span>            :   {
<span class="lineNum">     236 </span><span class="lineCov">          3 :    case '&quot;':  printf(&quot;\\\&quot;&quot;); break;</span>
<span class="lineNum">     237 </span><span class="lineCov">          3 :    case '\\': printf(&quot;\\\\&quot;); break;</span>
<span class="lineNum">     238 </span><span class="lineCov">          3 :    case '\a': printf(&quot;\\a&quot;); break;</span>
<span class="lineNum">     239 </span><span class="lineCov">          3 :    case '\b': printf(&quot;\\b&quot;); break;</span>
<span class="lineNum">     240 </span><span class="lineCov">          3 :    case '\f': printf(&quot;\\f&quot;); break;</span>
<span class="lineNum">     241 </span><span class="lineCov">          3 :    case '\n': printf(&quot;\\n&quot;); break;</span>
<span class="lineNum">     242 </span><span class="lineCov">          3 :    case '\r': printf(&quot;\\r&quot;); break;</span>
<span class="lineNum">     243 </span><span class="lineCov">          3 :    case '\t': printf(&quot;\\t&quot;); break;</span>
<span class="lineNum">     244 </span><span class="lineCov">          3 :    case '\v': printf(&quot;\\v&quot;); break;</span>
<span class="lineNum">     245 </span><span class="lineCov">        192 :    default:     if (isprint(c))</span>
<span class="lineNum">     246 </span><span class="lineCov">        189 :                         printf(&quot;%c&quot;,c);</span>
<span class="lineNum">     247 </span>            :                 else
<span class="lineNum">     248 </span><span class="lineCov">          3 :                         printf(&quot;\\%03d&quot;,c);</span>
<span class="lineNum">     249 </span>            :   }
<span class="lineNum">     250 </span>            :  }
<span class="lineNum">     251 </span><span class="lineCov">         44 :  printf(&quot;%c&quot;,'&quot;');</span>
<span class="lineNum">     252 </span><span class="lineCov">         44 : }</span>
<span class="lineNum">     253 </span>            : 
<span class="lineNum">     254 </span><span class="lineCov">         58 : static void PrintConstant(const Proto* f, int i)</span>
<span class="lineNum">     255 </span>            : {
<span class="lineNum">     256 </span><span class="lineCov">         58 :  const TValue* o=&amp;f-&gt;k[i];</span>
<span class="lineNum">     257 </span><span class="lineCov">         58 :  switch (ttype(o))</span>
<span class="lineNum">     258 </span>            :  {
<span class="lineNum">     259 </span><span class="lineCov">          3 :   case LUA_TNIL:</span>
<span class="lineNum">     260 </span><span class="lineCov">          3 :         printf(&quot;nil&quot;);</span>
<span class="lineNum">     261 </span><span class="lineCov">          3 :         break;</span>
<span class="lineNum">     262 </span><span class="lineCov">          3 :   case LUA_TBOOLEAN:</span>
<span class="lineNum">     263 </span><span class="lineCov">          3 :         printf(bvalue(o) ? &quot;true&quot; : &quot;false&quot;);</span>
<span class="lineNum">     264 </span><span class="lineCov">          3 :         break;</span>
<span class="lineNum">     265 </span><span class="lineCov">          3 :   case LUA_TNUMFLT:</span>
<span class="lineNum">     266 </span>            :         {
<span class="lineNum">     267 </span>            :         char buff[100];
<span class="lineNum">     268 </span><span class="lineCov">          3 :         sprintf(buff,LUA_NUMBER_FMT,fltvalue(o));</span>
<span class="lineNum">     269 </span><span class="lineCov">          3 :         printf(&quot;%s&quot;,buff);</span>
<span class="lineNum">     270 </span><span class="lineCov">          3 :         if (buff[strspn(buff,&quot;-0123456789&quot;)]=='\0') printf(&quot;.0&quot;);</span>
<span class="lineNum">     271 </span><span class="lineCov">          3 :         break;</span>
<span class="lineNum">     272 </span>            :         }
<span class="lineNum">     273 </span><span class="lineCov">          5 :   case LUA_TNUMINT:</span>
<span class="lineNum">     274 </span><span class="lineCov">          5 :         printf(LUA_INTEGER_FMT,ivalue(o));</span>
<span class="lineNum">     275 </span><span class="lineCov">          5 :         break;</span>
<span class="lineNum">     276 </span><span class="lineCov">         44 :   case LUA_TSHRSTR: case LUA_TLNGSTR:</span>
<span class="lineNum">     277 </span><span class="lineCov">         44 :         PrintString(tsvalue(o));</span>
<span class="lineNum">     278 </span><span class="lineCov">         44 :         break;</span>
<span class="lineNum">     279 </span><span class="lineNoCov">          0 :   default:                              /* cannot happen */</span>
<span class="lineNum">     280 </span><span class="lineNoCov">          0 :         printf(&quot;? type=%d&quot;,ttype(o));</span>
<span class="lineNum">     281 </span><span class="lineNoCov">          0 :         break;</span>
<span class="lineNum">     282 </span>            :  }
<span class="lineNum">     283 </span><span class="lineCov">         58 : }</span>
<span class="lineNum">     284 </span>            : 
<span class="lineNum">     285 </span>            : #define UPVALNAME(x) ((f-&gt;upvalues[x].name) ? getstr(f-&gt;upvalues[x].name) : &quot;-&quot;)
<span class="lineNum">     286 </span>            : #define MYK(x)          (-1-(x))
<span class="lineNum">     287 </span>            : 
<span class="lineNum">     288 </span><span class="lineCov">          8 : static void PrintCode(const Proto* f)</span>
<span class="lineNum">     289 </span>            : {
<span class="lineNum">     290 </span><span class="lineCov">          8 :  const Instruction* code=f-&gt;code;</span>
<span class="lineNum">     291 </span><span class="lineCov">          8 :  int pc,n=f-&gt;sizecode;</span>
<span class="lineNum">     292 </span><span class="lineCov">         68 :  for (pc=0; pc&lt;n; pc++)</span>
<span class="lineNum">     293 </span>            :  {
<span class="lineNum">     294 </span><span class="lineCov">         60 :   Instruction i=code[pc];</span>
<span class="lineNum">     295 </span><span class="lineCov">         60 :   OpCode o=GET_OPCODE(i);</span>
<span class="lineNum">     296 </span><span class="lineCov">         60 :   int a=GETARG_A(i);</span>
<span class="lineNum">     297 </span><span class="lineCov">         60 :   int b=GETARG_B(i);</span>
<span class="lineNum">     298 </span><span class="lineCov">         60 :   int c=GETARG_C(i);</span>
<span class="lineNum">     299 </span><span class="lineCov">         60 :   int ax=GETARG_Ax(i);</span>
<span class="lineNum">     300 </span><span class="lineCov">         60 :   int bx=GETARG_Bx(i);</span>
<span class="lineNum">     301 </span><span class="lineCov">         60 :   int sbx=GETARG_sBx(i);</span>
<span class="lineNum">     302 </span><span class="lineCov">         60 :   int line=getfuncline(f,pc);</span>
<span class="lineNum">     303 </span><span class="lineCov">         60 :   printf(&quot;\t%d\t&quot;,pc+1);</span>
<span class="lineNum">     304 </span><span class="lineCov">         60 :   if (line&gt;0) printf(&quot;[%d]\t&quot;,line); else printf(&quot;[-]\t&quot;);</span>
<span class="lineNum">     305 </span><span class="lineCov">         60 :   printf(&quot;%-9s\t&quot;,luaP_opnames[o]);</span>
<span class="lineNum">     306 </span><span class="lineCov">         60 :   switch (getOpMode(o))</span>
<span class="lineNum">     307 </span>            :   {
<span class="lineNum">     308 </span><span class="lineCov">         44 :    case iABC:</span>
<span class="lineNum">     309 </span><span class="lineCov">         44 :     printf(&quot;%d&quot;,a);</span>
<span class="lineNum">     310 </span><span class="lineCov">         44 :     if (getBMode(o)!=OpArgN) printf(&quot; %d&quot;,ISK(b) ? (MYK(INDEXK(b))) : b);</span>
<span class="lineNum">     311 </span><span class="lineCov">         44 :     if (getCMode(o)!=OpArgN) printf(&quot; %d&quot;,ISK(c) ? (MYK(INDEXK(c))) : c);</span>
<span class="lineNum">     312 </span><span class="lineCov">         44 :     break;</span>
<span class="lineNum">     313 </span><span class="lineCov">         14 :    case iABx:</span>
<span class="lineNum">     314 </span><span class="lineCov">         14 :     printf(&quot;%d&quot;,a);</span>
<span class="lineNum">     315 </span><span class="lineCov">         14 :     if (getBMode(o)==OpArgK) printf(&quot; %d&quot;,MYK(bx));</span>
<span class="lineNum">     316 </span><span class="lineCov">         14 :     if (getBMode(o)==OpArgU) printf(&quot; %d&quot;,bx);</span>
<span class="lineNum">     317 </span><span class="lineCov">         14 :     break;</span>
<span class="lineNum">     318 </span><span class="lineCov">          2 :    case iAsBx:</span>
<span class="lineNum">     319 </span><span class="lineCov">          2 :     printf(&quot;%d %d&quot;,a,sbx);</span>
<span class="lineNum">     320 </span><span class="lineCov">          2 :     break;</span>
<span class="lineNum">     321 </span><span class="lineNoCov">          0 :    case iAx:</span>
<span class="lineNum">     322 </span><span class="lineNoCov">          0 :     printf(&quot;%d&quot;,MYK(ax));</span>
<span class="lineNum">     323 </span><span class="lineNoCov">          0 :     break;</span>
<span class="lineNum">     324 </span>            :   }
<span class="lineNum">     325 </span><span class="lineCov">         60 :   switch (o)</span>
<span class="lineNum">     326 </span>            :   {
<span class="lineNum">     327 </span><span class="lineCov">         12 :    case OP_LOADK:</span>
<span class="lineNum">     328 </span><span class="lineCov">         12 :     printf(&quot;\t; &quot;); PrintConstant(f,bx);</span>
<span class="lineNum">     329 </span><span class="lineCov">         12 :     break;</span>
<span class="lineNum">     330 </span><span class="lineCov">          2 :    case OP_GETUPVAL:</span>
<span class="lineNum">     331 </span>            :    case OP_SETUPVAL:
<span class="lineNum">     332 </span><span class="lineCov">          2 :     printf(&quot;\t; %s&quot;,UPVALNAME(b));</span>
<span class="lineNum">     333 </span><span class="lineCov">          2 :     break;</span>
<span class="lineNum">     334 </span><span class="lineCov">          8 :    case OP_GETTABUP:</span>
<span class="lineNum">     335 </span><span class="lineCov">          8 :     printf(&quot;\t; %s&quot;,UPVALNAME(b));</span>
<span class="lineNum">     336 </span><span class="lineCov">          8 :     if (ISK(c)) { printf(&quot; &quot;); PrintConstant(f,INDEXK(c)); }</span>
<span class="lineNum">     337 </span><span class="lineCov">          8 :     break;</span>
<span class="lineNum">     338 </span><span class="lineCov">          8 :    case OP_SETTABUP:</span>
<span class="lineNum">     339 </span><span class="lineCov">          8 :     printf(&quot;\t; %s&quot;,UPVALNAME(a));</span>
<span class="lineNum">     340 </span><span class="lineCov">          8 :     if (ISK(b)) { printf(&quot; &quot;); PrintConstant(f,INDEXK(b)); }</span>
<span class="lineNum">     341 </span><span class="lineCov">          8 :     if (ISK(c)) { printf(&quot; &quot;); PrintConstant(f,INDEXK(c)); }</span>
<span class="lineNum">     342 </span><span class="lineCov">          8 :     break;</span>
<span class="lineNum">     343 </span><span class="lineCov">          2 :    case OP_GETTABLE:</span>
<span class="lineNum">     344 </span>            :    case OP_SELF:
<span class="lineNum">     345 </span><span class="lineCov">          2 :     if (ISK(c)) { printf(&quot;\t; &quot;); PrintConstant(f,INDEXK(c)); }</span>
<span class="lineNum">     346 </span><span class="lineCov">          2 :     break;</span>
<span class="lineNum">     347 </span><span class="lineCov">          4 :    case OP_SETTABLE:</span>
<span class="lineNum">     348 </span>            :    case OP_ADD:
<span class="lineNum">     349 </span>            :    case OP_SUB:
<span class="lineNum">     350 </span>            :    case OP_MUL:
<span class="lineNum">     351 </span>            :    case OP_MOD:
<span class="lineNum">     352 </span>            :    case OP_POW:
<span class="lineNum">     353 </span>            :    case OP_DIV:
<span class="lineNum">     354 </span>            :    case OP_IDIV:
<span class="lineNum">     355 </span>            :    case OP_BAND:
<span class="lineNum">     356 </span>            :    case OP_BOR:
<span class="lineNum">     357 </span>            :    case OP_BXOR:
<span class="lineNum">     358 </span>            :    case OP_SHL:
<span class="lineNum">     359 </span>            :    case OP_SHR:
<span class="lineNum">     360 </span>            :    case OP_EQ:
<span class="lineNum">     361 </span>            :    case OP_LT:
<span class="lineNum">     362 </span>            :    case OP_LE:
<span class="lineNum">     363 </span><span class="lineCov">          4 :     if (ISK(b) || ISK(c))</span>
<span class="lineNum">     364 </span>            :     {
<span class="lineNum">     365 </span><span class="lineCov">          4 :      printf(&quot;\t; &quot;);</span>
<span class="lineNum">     366 </span><span class="lineCov">          4 :      if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf(&quot;-&quot;);</span>
<span class="lineNum">     367 </span><span class="lineCov">          4 :      printf(&quot; &quot;);</span>
<span class="lineNum">     368 </span><span class="lineCov">          4 :      if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf(&quot;-&quot;);</span>
<span class="lineNum">     369 </span>            :     }
<span class="lineNum">     370 </span><span class="lineCov">          4 :     break;</span>
<span class="lineNum">     371 </span><span class="lineCov">          2 :    case OP_JMP:</span>
<span class="lineNum">     372 </span>            :    case OP_FORLOOP:
<span class="lineNum">     373 </span>            :    case OP_FORPREP:
<span class="lineNum">     374 </span>            :    case OP_TFORLOOP:
<span class="lineNum">     375 </span><span class="lineCov">          2 :     printf(&quot;\t; to %d&quot;,sbx+pc+2);</span>
<span class="lineNum">     376 </span><span class="lineCov">          2 :     break;</span>
<span class="lineNum">     377 </span><span class="lineCov">          2 :    case OP_CLOSURE:</span>
<span class="lineNum">     378 </span><span class="lineCov">          2 :     printf(&quot;\t; %p&quot;,VOID(f-&gt;p[bx]));</span>
<span class="lineNum">     379 </span><span class="lineCov">          2 :     break;</span>
<span class="lineNum">     380 </span><span class="lineCov">          2 :    case OP_SETLIST:</span>
<span class="lineNum">     381 </span><span class="lineCov">          2 :     if (c==0) printf(&quot;\t; %d&quot;,(int)code[++pc]); else printf(&quot;\t; %d&quot;,c);</span>
<span class="lineNum">     382 </span><span class="lineCov">          2 :     break;</span>
<span class="lineNum">     383 </span><span class="lineNoCov">          0 :    case OP_EXTRAARG:</span>
<span class="lineNum">     384 </span><span class="lineNoCov">          0 :     printf(&quot;\t; &quot;); PrintConstant(f,ax);</span>
<span class="lineNum">     385 </span><span class="lineNoCov">          0 :     break;</span>
<span class="lineNum">     386 </span><span class="lineCov">         18 :    default:</span>
<span class="lineNum">     387 </span><span class="lineCov">         18 :     break;</span>
<span class="lineNum">     388 </span>            :   }
<span class="lineNum">     389 </span><span class="lineCov">         60 :   printf(&quot;\n&quot;);</span>
<span class="lineNum">     390 </span>            :  }
<span class="lineNum">     391 </span><span class="lineCov">          8 : }</span>
<span class="lineNum">     392 </span>            : 
<span class="lineNum">     393 </span>            : #define SS(x)   ((x==1)?&quot;&quot;:&quot;s&quot;)
<span class="lineNum">     394 </span>            : #define S(x)    (int)(x),SS(x)
<span class="lineNum">     395 </span>            : 
<span class="lineNum">     396 </span><span class="lineCov">          8 : static void PrintHeader(const Proto* f)</span>
<span class="lineNum">     397 </span>            : {
<span class="lineNum">     398 </span><span class="lineCov">          8 :  const char* s=f-&gt;source ? getstr(f-&gt;source) : &quot;=?&quot;;</span>
<span class="lineNum">     399 </span><span class="lineCov">          8 :  if (*s=='@' || *s=='=')</span>
<span class="lineNum">     400 </span><span class="lineCov">          8 :   s++;</span>
<span class="lineNum">     401 </span><span class="lineNoCov">          0 :  else if (*s==LUA_SIGNATURE[0])</span>
<span class="lineNum">     402 </span><span class="lineNoCov">          0 :   s=&quot;(bstring)&quot;;</span>
<span class="lineNum">     403 </span>            :  else
<span class="lineNum">     404 </span><span class="lineNoCov">          0 :   s=&quot;(string)&quot;;</span>
<span class="lineNum">     405 </span><span class="lineCov">         16 :  printf(&quot;\n%s &lt;%s:%d,%d&gt; (%d instruction%s at %p)\n&quot;,</span>
<span class="lineNum">     406 </span><span class="lineCov">          8 :         (f-&gt;linedefined==0)?&quot;main&quot;:&quot;function&quot;,s,</span>
<span class="lineNum">     407 </span>            :         f-&gt;linedefined,f-&gt;lastlinedefined,
<span class="lineNum">     408 </span><span class="lineCov">         16 :         S(f-&gt;sizecode),VOID(f));</span>
<span class="lineNum">     409 </span><span class="lineCov">         32 :  printf(&quot;%d%s param%s, %d slot%s, %d upvalue%s, &quot;,</span>
<span class="lineNum">     410 </span><span class="lineCov">         16 :         (int)(f-&gt;numparams),f-&gt;is_vararg?&quot;+&quot;:&quot;&quot;,SS(f-&gt;numparams),</span>
<span class="lineNum">     411 </span><span class="lineCov">         24 :         S(f-&gt;maxstacksize),S(f-&gt;sizeupvalues));</span>
<span class="lineNum">     412 </span><span class="lineCov">         24 :  printf(&quot;%d local%s, %d constant%s, %d function%s\n&quot;,</span>
<span class="lineNum">     413 </span><span class="lineCov">         32 :         S(f-&gt;sizelocvars),S(f-&gt;sizek),S(f-&gt;sizep));</span>
<span class="lineNum">     414 </span><span class="lineCov">          8 : }</span>
<span class="lineNum">     415 </span>            : 
<span class="lineNum">     416 </span><span class="lineCov">          3 : static void PrintDebug(const Proto* f)</span>
<span class="lineNum">     417 </span>            : {
<span class="lineNum">     418 </span>            :  int i,n;
<span class="lineNum">     419 </span><span class="lineCov">          3 :  n=f-&gt;sizek;</span>
<span class="lineNum">     420 </span><span class="lineCov">          3 :  printf(&quot;constants (%d) for %p:\n&quot;,n,VOID(f));</span>
<span class="lineNum">     421 </span><span class="lineCov">         19 :  for (i=0; i&lt;n; i++)</span>
<span class="lineNum">     422 </span>            :  {
<span class="lineNum">     423 </span><span class="lineCov">         16 :   printf(&quot;\t%d\t&quot;,i+1);</span>
<span class="lineNum">     424 </span><span class="lineCov">         16 :   PrintConstant(f,i);</span>
<span class="lineNum">     425 </span><span class="lineCov">         16 :   printf(&quot;\n&quot;);</span>
<span class="lineNum">     426 </span>            :  }
<span class="lineNum">     427 </span><span class="lineCov">          3 :  n=f-&gt;sizelocvars;</span>
<span class="lineNum">     428 </span><span class="lineCov">          3 :  printf(&quot;locals (%d) for %p:\n&quot;,n,VOID(f));</span>
<span class="lineNum">     429 </span><span class="lineCov">          7 :  for (i=0; i&lt;n; i++)</span>
<span class="lineNum">     430 </span>            :  {
<span class="lineNum">     431 </span><span class="lineCov">         12 :   printf(&quot;\t%d\t%s\t%d\t%d\n&quot;,</span>
<span class="lineNum">     432 </span><span class="lineCov">          4 :   i,getstr(f-&gt;locvars[i].varname),f-&gt;locvars[i].startpc+1,f-&gt;locvars[i].endpc+1);</span>
<span class="lineNum">     433 </span>            :  }
<span class="lineNum">     434 </span><span class="lineCov">          3 :  n=f-&gt;sizeupvalues;</span>
<span class="lineNum">     435 </span><span class="lineCov">          3 :  printf(&quot;upvalues (%d) for %p:\n&quot;,n,VOID(f));</span>
<span class="lineNum">     436 </span><span class="lineCov">          7 :  for (i=0; i&lt;n; i++)</span>
<span class="lineNum">     437 </span>            :  {
<span class="lineNum">     438 </span><span class="lineCov">          4 :   printf(&quot;\t%d\t%s\t%d\t%d\n&quot;,</span>
<span class="lineNum">     439 </span><span class="lineCov">          4 :   i,UPVALNAME(i),f-&gt;upvalues[i].instack,f-&gt;upvalues[i].idx);</span>
<span class="lineNum">     440 </span>            :  }
<span class="lineNum">     441 </span><span class="lineCov">          3 : }</span>
<span class="lineNum">     442 </span>            : 
<span class="lineNum">     443 </span><span class="lineCov">          8 : static void PrintFunction(const Proto* f, int full)</span>
<span class="lineNum">     444 </span>            : {
<span class="lineNum">     445 </span><span class="lineCov">          8 :  int i,n=f-&gt;sizep;</span>
<span class="lineNum">     446 </span><span class="lineCov">          8 :  PrintHeader(f);</span>
<span class="lineNum">     447 </span><span class="lineCov">          8 :  PrintCode(f);</span>
<span class="lineNum">     448 </span><span class="lineCov">          8 :  if (full) PrintDebug(f);</span>
<span class="lineNum">     449 </span><span class="lineCov">         10 :  for (i=0; i&lt;n; i++) PrintFunction(f-&gt;p[i],full);</span>
<span class="lineNum">     450 </span><span class="lineCov">          8 : }</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
